public class magics {
    public static void main(String[] args) {
        int i=0;
        int j=0;
        int m=0;
        int n=5;
        j=(n+1)/2-1;
        int [][]a=new int [n][n];
        a[i][j]=++m;
        while (m<n*n){
            i--;
            j++;
            if(m%n==0&&m>1){
                i+=2;
                j--;
            }
            if(i<0)
                i=i+n;
            if(j>n-1)
                j=j-n;
            a[i][j]=++m;
        }
        for (int k = 0; k < n; k++) {
            for (int l = 0; l < n; l++) {
                System.out.print(a[k][l]+" ");
            }
            System.out.println();
        }

    }
}
